﻿using Abp.Authorization.Users;
using Abp.Domain.Entities;
using Abp.Domain.Entities.Auditing;
using Abp.MultiTenancy;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using XHD.WXZJ.Authorization.Roles;
using XHD.WXZJ.Posts;

namespace XHD.WXZJ.Departments
{
    public class AbpDepartment<TTenant, TUser> : AbpDepartmentBase, IFullAudited<TUser>, IFullAudited, IDeletionAudited<TUser>, IDeletionAudited, ISoftDelete, IAudited<TUser>, IAudited, ICreationAudited<TUser>, ICreationAudited, IHasCreationTime, IModificationAudited<TUser>, IModificationAudited, IMayHaveTenant<TTenant, TUser>, IMayHaveTenant
        where TTenant : AbpTenant<TTenant, TUser>
        where TUser : AbpUser<TTenant, TUser>
    {
        /// <summary>
        /// 显示名称长度
        /// </summary>
        public const int MaxDisplayNameLength = 255;

        /// <summary>
        /// 名称校验规则
        /// </summary>
        public const string DepartmentNameRegex = "^[a-zA-Z][a-zA-Z0-9_-]{1,}$";

        /// <summary>
        /// The Tenant, if this Department is a tenant-level role.
        /// 
        /// </summary>
        [ForeignKey("TenantId")]
        public virtual TTenant Tenant { get; set; }


        //public virtual int DepartmentId { get; set; }
        
        [Required]
        [StringLength(255)]
        public virtual string DisplayName { get; set; }

        public virtual int IsStatic { get; set; }

        public virtual int IsDefault { get; set; }


        public ICollection<Post> Posts { get; set; }

        public virtual TUser DeleterUser { get; set; }

        public virtual TUser CreatorUser { get; set; }

        public virtual TUser LastModifierUser { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public AbpDepartment()
        {
            Name = Guid.NewGuid().ToString("N");
        }
        public AbpDepartment(int? tenantId, string displayName):this()
        {
           TenantId = tenantId;
           DisplayName = displayName;
        } 
        public AbpDepartment(int ? tenantId,string name,string displayName):this(tenantId,displayName)
        {
            Name = name;
        }

        public override string ToString()
        {
            return string.Format("[部门 {0}, 名称={1}]", (object)this.Id, (object)this.Name);
        }

    }
}
